package com.wang.springframework.context.annotation;

import cn.hutool.core.util.ClassUtil;
import com.wang.springframework.beans.factory.config.BeanDefinition;
import com.wang.springframework.stereotype.Component;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author wangjianhua
 * @Description 从basePackage中扫描路径得到Component的提供器 然后将排除和包含过滤器应用于查找候选类
 * @date 2021/9/3/003 17:25
 **/
public class ClassPathScanningCandidateComponentProvider {

    public Set<BeanDefinition> findCandidateComponents(String basePackage){
        Set<BeanDefinition> candidates = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);
        for (Class<?> clazz : classes) {
            candidates.add(new BeanDefinition(clazz));
        }
        return candidates;
    }
}
